package com.attendcollatesys.service.impl;


import com.attendcollatesys.entity.Employee;
import com.attendcollatesys.mapper.EmployeeMapper;
import com.attendcollatesys.service.EmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.DigestUtils;

import java.util.HashMap;
import java.util.Map;

@Service
public class EmployeeServiceImpl implements EmployeeService {

    @Autowired
    EmployeeMapper employeeMapper;


    @Override
    public Map<String,String> LoginVerificationMethod(String username, String password) {
        if (username == null || "".equals(username) || password == null || "".equals(password)){
            throw new RuntimeException("用户名或者密码为空！");
        }
        Employee employee = null;
        employee = employeeMapper.selectAccountPasswordStaPer(username);
        //这样就获取了内容
        if (employee == null || !username.equals(employee.getAccount())){
            throw new RuntimeException("登录失败 ！");
        }

        String passwordMy = DigestUtils.md5DigestAsHex(employee.getPassword().getBytes());

        Map<String,String> tResults = new HashMap<>();
        if (password.equals(passwordMy)){
            tResults.put("account",employee.getAccount());
            tResults.put("status",employee.getStatus());
            tResults.put("permission",employee.getPermission());
            return tResults;
        }else{
            throw new RuntimeException("无对应用户或者密码错误！");
        }
    }
}
